//https://www.bilibili.com/video/BV1d54y1f7B3/?spm_id_from=333.337.search-card.all.click&vd_source=d6fe65f095f01f05591e89d810720ccc
// 2024-10-19


import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class P011_有序数组两数之和_双指针法 {

    public static void main(String[] args) {
        System.out.println(Arrays.toString(fun(new int[]{1, 2, 3, 4, 5, 6}, 10)));
    }

    //nums顺序排列
    private static int[] fun(int[] nums,int target) {
        int i = 0,j = nums.length - 1;
        while (i <= j) {
            if (nums[i] + nums[j] == target)
                return new int[]{i,j};
            else if (nums[i] + nums[j] < target)
                i++;
            else
                j--;
        }
        return null;
    }
}
